//
//  ViewController.swift
//  Recorder
//
//  Created by 魏滨 on 2020/4/2.
//  Copyright © 2020 魏滨. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    
    var path: String?
    

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }

    @IBAction func start(_ sender: Any) {
        Recorder.start(duration: 20) { model in
            print(model.elapsedDuration)
        } complete: { duration, path in
            print(duration, path)
            self.path = path
        } failure: { errMsg in
            print(errMsg)
        }
    }

    @IBAction func pusue(_ sender: Any) {
        Recorder.pause()
    }
    @IBAction func recoved(_ sender: Any) {
        Recorder.record()
    }
    @IBAction func stop(_ sender: Any) {
        Recorder.stop { duration, path in
            print(duration, path)
            self.path = path
        } failure: { errMsg in
            print(errMsg)
        }

    }

    @IBAction func play(_ sender: UIButton) {
        if let p = path {
            AudioPlayer.shared.play(path: p)
        }
    }
}

